<script type="text/javascript">

    function printPage(id) {
        //alert('successfully');
        var html = "<fieldset>";
        html += document.getElementById(id).innerHTML;
        html += "</fieldset>";

        var printWin = window.open('', '', 'left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status =0');
        printWin.document.write(html);
        printWin.document.close();
        printWin.focus();
        printWin.print();
        printWin.close();

        var html = "<html>";
        html += "<head>";
        // html+="<style type='text/css'>.mytable{border:1px solid #ccc;}.mytable tr{background-color:#008000;color:#FFF;}</style>";
        html += "<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/bootstrap.css' media='print' />";
        html += "<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/bootstrap-responsive.css' media='print' />";
        html += "<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/style.css' media='print' />";
        html += "<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/demo_table_jui.css' media='print' />";
        html += "</head>";
        html += document.getElementById(id).innerHTML;
        html += "</html>";

    }
</script>


<?php
echo '<fieldset id="year" style="border:1px solid #239DA9 ;margin: 0 auto;width:96%;height: auto; padding:20px;border-radius:5px;">';
echo '<div style="float:right; margin-right: 15px;">';
echo anchor('report/show_report', img('images/cancel.png'), array('title' => 'Back'));
echo '</div>';
?><div style=" height: 50px;  margin:10px;"><img src="<?php echo base_url(); ?>/images/login_logo.png" align="center"   alt="Print semester report" />
<?php
echo '<h1 style="color: #239DA9;
    font-family: verdana;
    font-size: 20px;
    font-style: italic;
    font-weight: bold;
    text-shadow: 1px 1px 1px #8483E1;
    margin-top:-50px;
    text-decoration: underline;
    text-align: center;">Leaving Report For ' . date("Y") . ' </h1></div>';
echo '<br/><div style="float:right;color:#239DA9;width:40%;text-align:right; margin-right: 15px; padding-bottom: 15px;">View Semester Report For  Year&nbsp;:' . '<b style="color:red;"> ' . date("Y") . '</b><br/>';
?>

    To print this report, Click here<a href="#">
        <img src="<?php echo base_url(); ?>/images/print.png" align="center" onclick="return printPage('year');" id="image"  alt="Print semester report" title="Print semester report"/>
    </a></div>
<table  cellpadding="0" cellspacing="0" border="1" style=" border: 1px solid #CCC; width: 1120px; text-align: center; margin: auto;" >
    <thead>
        <tr style="color: #239DA9;">
            <th colspan="6" style="height: 40px;">Detail</th>
            <th colspan="2">Type of Leave</th>
            <th colspan="3">Sub Type of Leave</th>
            <th>Totals</th>
        </tr>
        <tr style="color: #239DA9;">
            <th style="height: 40px;">Staff_Name</th>
            <th>Gender</th>
            <th>Department</th>
             <!--<th>Group</th>-->
            <th>Start_Date</th>
            <th>End_Date</th>
            <th>Annual</th>
            <th>Catch_Up</th>
            <th>Impossed</th>
            <th>Personal</th>
            <th>Special</th>
            <th>Sub</th>
        </tr>
    </thead>
    <tbody>
        <?php
        foreach ($staff->result_array() as $rows) {
            $staff_id = $rows['staff_id'];
            $this->db->select('*');
            $this->db->from('pnc_record');
            $this->db->where('staff_id', $staff_id);
            $this->db->where('YEAR( start_date ) = YEAR( CURDATE( ) ) and YEAR( end_date ) = YEAR( CURDATE( ) )');
            $year = $this->db->get();
            $gender = $rows['emp_gender'];
            $name = $rows['username'];
            $department = $rows['dept_name'];
//                $group=$rows['grp_name'];
            ?>
            <tr style="height: 40px;">
                <td><?php echo $name; ?></td>
                <td><?php echo $gender; ?></td>
                <td><?php echo $department; ?></td>
                <!--<td><?php echo $group; ?></td>-->
                <td><table class="table">
                        <?php
                        foreach ($year->result_array() as $subQuery) {
                            ?>
                            <tr><td><?php echo $subQuery['start_date']; ?> </td></tr>
                            <?php
                        }
                        ?> 
                    </table>
                </td>
                <td><table class="table "><?php
                    foreach ($year->result_array() as $subQuery) {
                            ?>
                            <tr ><td><?php echo $subQuery['end_date']; ?> </td></tr>
                            <?php }
                        ?>
                    </table>
                </td>
                <td><table class="table"><?php
                        foreach ($year->result_array() as $subQuery) {
                            ?><tr><?php
                            if ($subQuery['lea_id'] == 2) {
                                ?><td>&nbsp;</td><?php
                                } else {
                                    ?>
                                    <td><?php echo $subQuery['duration']; ?></td>
                                    <?php
                                }
                                ?></tr>

                            <?php
                        }
                        ?></table> 


                </td> 
                <td><table class="table"><?php
                    foreach ($year->result_array() as $subQuery) {
                        ?><tr><?php
                            if ($subQuery['lea_id'] == 1) {
                                ?><td>&nbsp;</td><?php
                                } else {
                                    ?>
                                    <td><?php echo $subQuery['duration']; ?></td>
                                    <?php
                                }
                                ?></tr>

                                <?php
                            }
                            ?></table></td>
                <td><table class="table"><?php
                        foreach ($year->result_array() as $subQuery) {
                            ?><tr><?php
                            if ($subQuery['stl_id'] == 2 || $subQuery['stl_id'] == 3 || $subQuery['stl_id'] == 0) {
                                ?><td>&nbsp;</td><?php
                            } else {
                                ?>
                                    <td><?php echo $subQuery['duration']; ?></td>
                                    <?php
                                }
                                ?></tr>

                                <?php
                            }
                            ?></table></td>
                <td><table class="table"><?php
                        foreach ($year->result_array() as $subQuery) {
                                ?><tr><?php
                            if ($subQuery['stl_id'] == 1 || $subQuery['stl_id'] == 3 || $subQuery['stl_id'] == 0) {
                                ?><td>&nbsp;</td><?php
                            } else {
                                ?>
                                    <td><?php echo $subQuery['duration']; ?></td>
                                <?php
                                }
                                ?></tr>

                                <?php
                            }
                            ?></table></td>
                <td><table class="table">
                            <?php
                            foreach ($year->result_array() as $subQuery) {
                                ?><tr><?php
                            if ($subQuery['stl_id'] == 2 || $subQuery['stl_id'] == 1 || $subQuery['stl_id'] == 0) {
                                ?><td>&nbsp;</td><?php
                            } else {
                                ?>
                                    <td><?php echo $subQuery['duration']; ?></td>
                                <?php
                            }
                            ?></tr>


                                <?php
                            }
                            ?>
                    </table></td>
                <td>
                            <?php
                            $annul = 0;
                            $catch_up = 0;
//           $mysql_1 = "SELECT *FROM pnc_record WHERE staff_id={$staff_id} and YEAR( start_date ) = YEAR( CURDATE( ) ) and YEAR( end_date ) = YEAR( CURDATE( ) )";
//               $result_1 = mysql_query($mysql_1);
//                    while ($subQuery = mysql_fetch_array($result_1)) {
                            foreach ($year->result_array() as $subQuery) {
                                $type_id = $subQuery['lea_id'];
                                $id = $subQuery ['duration'];

                                if ($type_id == 1) {
                                    $annul = $id + $annul;
                                } else if ($type_id == 2) {
                                    $catch_up = $id + $catch_up;
                                }


                                $totals = $annul + $catch_up;
                            } echo '<b style="color:red;">' . $totals . '</b>';
                            ?>
                </td>             


            </tr>
                    <?php
                }
                ?>
    </tbody> 
</table>
</br>


</fieldset>
